/*
*	Project: Aethon
*
*	File: Model.cpp
*
*	Author: Robert Whiting
*
*	Date: 2/11/2009
*
*	Purpose: The model contains information for objects within the scene,
*	including physical attributes, physics attributes, and the model part
*	root item
*/

#include "../include/Model.h"

void Model::display(void){
	glPushMatrix();
    glTranslatef(position.v[0],position.v[1],position.v[2]);
    glRotated(direction.v[0],0,0,1);
    glRotated(direction.v[1],0,1,0);
    glRotated(direction.v[2],1,0,0);
	rootModelPart.display();
    glPopMatrix();
}//end display

void Model::load(string filename){
	printf("Model::load '%s'\n", filename.c_str());
	filename = "../data/models/" + filename + ".m";
	ifstream inData;
	inData.open(filename.c_str());
	string token;
    if(!inData)
    	printf("Data file failed\n");
    char comment = inData.peek();
    //read all comments
    while(comment == '#'){
		inData.ignore(100,'\n');
		comment = inData.peek();
    }
	//gravity, visability, collisionSphereRadius
	float collisionSphereRadius;
	inData >> hasGravity >> hasVisibility >> collisionSphereRadius;
	collisionSphere.setRadius(collisionSphereRadius);
    //position
    float pos[3];
	inData >> pos[0] >> pos[1] >> pos[2];
	position = vector3f(pos);
	//direction
	float dir[3];
	inData >> dir[0] >> dir[1] >> dir[2];
	direction = vector3f(dir);
	//velocity
	float vel[3];
	inData >> vel[0] >> vel[1] >> vel[2];
	velocity = vector3f(vel);
	//modelPartFilename name
	string modelPartFilename = "";
	inData >> modelPartFilename;
	fprintf(stderr, "filename read in\n");
	rootModelPart.load(modelPartFilename);
    inData.close();
	printf("Loading '%s' complete\n", filename.c_str());
}//end load

